/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.leadiv.ai.minesweeper.util;

/**
 *
 * @author pborrego
 */
public class Utils {
    public Utils()
    {
        
    }
    
    // returns a random integer between x <= n <= y
    public static int RandInt(int x,int y) 
    {
        return (int)(Math.random()* Math.abs(y-x+1))+x;
    }

    // returns a random float between 0 <= n < 1.
    // basically an alias of Math.random()
    public static double RandFloat()
    {
        return Math.random();
    }

    // returns a random boolean
    public static boolean RandBool()
    {
        return RandInt(0,1) == 1 ? true : false;
    }

    //returns a random float in the range -1 < n < 1
    public static double RandomClamped()
    {
        return RandFloat() - RandFloat();
    }


    //-----------------------------------------------------------------------
    //	
    //	some handy little functions
    //-----------------------------------------------------------------------

    //converts an integer to a String. Just an alias of Integer.toString
    public static String itos(int arg)
    {
        return Integer.toString(arg);
    }

    //converts an float to a String. Just an alias of Float.toString
    public static String ftos (float arg)
    {
        return Float.toString(arg);
    }

    // The arg value is modified if it is below the min threshold 
    //    or above the max threshold
    public static double Clamp(double arg, double min, double max)
    {
        if (arg < min)
        {
            arg = min;
        }

        if (arg > max)
        {
            arg = max;
        }

        return arg;
    }
}
